package com.he.config.druid;

import com.alibaba.druid.support.http.StatViewServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @description: TODO
 * @Author: HCL
 * @Date: 2024/11/22 9:55
 */
@Configuration
public class DruidMonitorConfig {

    @Bean("MyDruidStatViewServlet")
    public ServletRegistrationBean<StatViewServlet> getDruidStatViewServlet(){
        ServletRegistrationBean<StatViewServlet> registrationBean = new ServletRegistrationBean<>(
                new StatViewServlet(),
                "/druid/*"
        );
        registrationBean.addInitParameter(StatViewServlet.PARAM_NAME_ALLOW, "127.0.0.1");//设置访问白名单
        registrationBean.addInitParameter(StatViewServlet.PARAM_NAME_DENY, "");//设置访问黑名单，拒绝访问
        registrationBean.addInitParameter(StatViewServlet.PARAM_NAME_USERNAME, "druid");//用户名
        registrationBean.addInitParameter(StatViewServlet.PARAM_NAME_PASSWORD, "druid");//密码
        registrationBean.addInitParameter(StatViewServlet.PARAM_NAME_RESET_ENABLE, "true");//允许充值
        return registrationBean;
    }
}
